package kr.hkit.androidcomplete01.ch09;

import kr.hkit.androidcomplete01.R;
import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.util.AttributeSet;
import android.view.*;
import android.view.ContextMenu.ContextMenuInfo;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;

public class ContextMenuTest extends Activity {
	private Button mBtn;
	private EditText mEdit;
	private MyImage mImage;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch09_contextmenutest);
		
		mBtn = (Button) findViewById(R.id.button);
		registerForContextMenu(mBtn);
		
		mEdit = (EditText) findViewById(R.id.edittext);
		registerForContextMenu(mEdit);
		
		mImage = (MyImage) findViewById(R.id.myimage);
		registerForContextMenu(mImage);
	}
	@Override
	public void onCreateContextMenu(ContextMenu menu, View v,
			ContextMenuInfo menuInfo) {
		// TODO Auto-generated method stub
		super.onCreateContextMenu(menu, v, menuInfo);
		if (v == mBtn) {
			menu.setHeaderTitle("Button Menu");
			menu.add(0,1,0,"Red");
			menu.add(0,2,0,"Green");
			menu.add(0,3,0,"Blue");
		}

		if (v == mEdit) {
			menu.add(0,4,0,"번역하기");
			menu.add(0,5,0,"필기 인식");
		}
	}

	@Override
	public boolean onContextItemSelected(MenuItem item) {
		switch(item.getItemId()){
		case 1:
			mBtn.setTextColor(Color.RED);
			return true;
		case 2:
			mBtn.setTextColor(Color.GREEN);
			return true;
		case 3:
			mBtn.setTextColor(Color.BLUE);
			return true;
		case 4:
			Toast.makeText(this, "번역했다", Toast.LENGTH_SHORT).show();	
			return true;
		case 5:
			Toast.makeText(this, "필기인식했다", Toast.LENGTH_SHORT).show();
			return true;
		case 100:
			Toast.makeText(this, "회전했다 치고", Toast.LENGTH_SHORT).show();	
			return true;
		case 101:
			Toast.makeText(this, "크기 변경했다 치고", Toast.LENGTH_SHORT).show();	
			return true;
		}
		
		return true;
	}
}
